feat(backend): packed-quant matmul dispatch in DefaultCpuOpsBase (wor…#711
Merged
Conversation
…ks on Native) Part of #708. Makes `ops.matmul(x, ops.transpose(W))` route packed-quant weights to a kernel on EVERY KMP target. Before this, the packed-quant matmul dispatch + lazy transpose lived only in DefaultCpuOpsJvm, so on Kotlin/Native/JS/WASM a packed weight fell through to matmulGeneric, which throws on Byte-packed data — packed matmul was effectively broken off-JVM. - New Q5_1/Q5_0 packed tensor-data types + TensorEncoding.Q5_0/Q5_1 (lang-core). - DefaultCpuOpsBase: `chooseQuantizedMatmulHeap` resolves the kernel via the commonMain KernelRegistry (scalar floor on Native/JS/WASM; Panama/FFM on JVM via the ensureKernelProviders() hook + ServiceLoader) and dispatches FP32 × packed {Q8_0,Q4_0,Q4_K,Q6_K,Q5_1,Q5_0}; lazy-transpose shape-swap branches for the four heap K/Q5 types. The JVM ops keep their MemSeg/SIMD fast paths and intercept Q4_K/Q6_K/Q8_0/Q4_0 before the base — zero JVM regression by construction; Q5_1/Q5_0 (and the whole set on non-JVM) resolve in the base. - Non-JVM platform factories (linux/apple/js/wasm/wasmWasi/android) register ScalarKernelProvider (no ServiceLoader off-JVM). Tests: PackedMatmulDispatchTest (commonTest) runs Q4_K + Q5_1 through ctx.ops.matmul(x, transpose(W)) and matches the dequant reference — green on jvmTest AND linuxX64Test (the Native end-to-end proof). Full backend-cpu jvmTest suite passes (no regression); apiDump regenerated for lang-core + backend-cpu. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…-quant-kernels # Conflicts: # skainet-lang/skainet-lang-core/src/commonMain/kotlin/sk/ainet/lang/tensor/data/Q5_0TensorData.kt # skainet-lang/skainet-lang-core/src/commonMain/kotlin/sk/ainet/lang/tensor/data/Q5_1TensorData.kt
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
This was referenced Jun 8, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…ks on Native)
Part of #708. Makes
ops.matmul(x, ops.transpose(W))route packed-quant weights to a kernel on EVERY KMP target. Before this, the packed-quant matmul dispatch + lazy transpose lived only in DefaultCpuOpsJvm, so on Kotlin/Native/JS/WASM a packed weight fell through to matmulGeneric, which throws on Byte-packed data — packed matmul was effectively broken off-JVM.chooseQuantizedMatmulHeapresolves the kernel via the commonMain KernelRegistry (scalar floor on Native/JS/WASM; Panama/FFM on JVM via the ensureKernelProviders() hook + ServiceLoader) and dispatches FP32 × packed {Q8_0,Q4_0,Q4_K,Q6_K,Q5_1,Q5_0}; lazy-transpose shape-swap branches for the four heap K/Q5 types. The JVM ops keep their MemSeg/SIMD fast paths and intercept Q4_K/Q6_K/Q8_0/Q4_0 before the base — zero JVM regression by construction; Q5_1/Q5_0 (and the whole set on non-JVM) resolve in the base.Tests: PackedMatmulDispatchTest (commonTest) runs Q4_K + Q5_1 through ctx.ops.matmul(x, transpose(W)) and matches the dequant reference — green on jvmTest AND linuxX64Test (the Native end-to-end proof). Full backend-cpu jvmTest suite passes (no regression); apiDump regenerated for lang-core + backend-cpu.